#{extends 'Admin_main.html' /}
<div class="block span10" style="margin-left: 20px;">
    <a href="#tablewidget" class="block-heading" data-toggle="collapse">菜单管理</a>
    <div class="btn-toolbar" style="margin-left: 20px;">

        <a href="" class="btn btn-primary">导入</a>
        <a href="" class="btn btn-primary">导出</a>
        <a href="#myModal" data-toggle="modal" class="btn">删除</a>
        <div class="btn-group">
        </div>
    </div>
    <div id="tablewidget" class="block-body collapse in" >
        <table class="table table-bordered table-striped">

            <tr>
                <th>操作</th>
                <th>编号</th>
                <th>菜单地址</th>
                <th>菜单名称</th>
            </tr>
            #{list meun,as:'meuns'}
            <tr>

                <td><input type="checkbox" class="caozuo" value="${meuns.Id}"></td>
                <td>${meuns.Id}</td>
                <td>${meuns.MeunId}</td>
                <td>${meuns.MenuName}</td>
            </tr>
            #{/list}
        </table>
        <p>
        <ul>
            <li>
                共 ${size} 条记录 共 ${number} 页
            </li>
            <li>
                当前第 1 页
            </li>
             <li>
             #{if number==0}
                 <a href="/admin/user/index?pageSize=${pageSize}">上一页</a>
             #{/if}
             #{elseif number==pageSize+1}
                 <a href="/admin/user/index?pageSize=${pageSize-1}">上一页</a>
             #{/elseif}
             #{elseif number<pageSize+1}
                 <a href="/admin/user/index?pageSize=${number}">上一页</a>
             #{/elseif}
             </li>
             <li>
                #{if number==0}
                    <a href="/admin/user/index?pageSize=${pageSize}">下一页</a>
                #{/if}
                 #{elseif number==pageSize+1}
                     <a href="/admin/user/index?pageSize=${pageSize}">下一页</a>
                 #{/elseif}
                 #{elseif number>pageSize+1}
                     <a href="/admin/user/index?pageSize=${pageSize+1}">下一页</a>
                 #{/elseif}
             </li>
        </ul>
        </p>

    </div>
    <div class="well" style="padding: 20px;margin: 20px;">
        <ul class="nav nav-tabs">
            <li  id="hoems" class="active"><a href="#home" data-toggle="tab">增加</a></li>
            <li id="profiles"><a href="#profile" data-toggle="tab" >修改</a></li>
        </ul>
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane active in" id="home">
                <form id="tab">
                    <label>菜单地址</label>
                    <input type="text" value="" id="meunId" class="input-xlarge">
                    <label>菜单名称</label>
                    <input type="text" value="" id="MenuName" class="input-xlarge">
                    <input type="button" id="add" class="btn btn-primary pull-right" value="提交">
                </form>
            </div>
            <div class="tab-pane fade" id="profile">
                <form id="tab">
                    <label>菜单地址</label>
                    <input type="text" value=""  id="meunIds"  class="input-xlarge">
                    <label>菜单名称</label>
                    <input type="text" value="" id="MenuNames" class="input-xlarge">
                    <input type="hidden" id="ids">
                    <input type="button" class="btn btn-primary pull-right"id="edits" value="提交">
                </form>
            </div>
        </div>

    </div>
</div>
<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">删除数据</h3>
    </div>
    <div class="modal-body">

        <p class="error-text"><i class="icon-warning-sign modal-icon"></i>你真的要删除该用户数据吗?</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
        <button class="btn btn-danger" data-dismiss="modal" id="delete">删除</button>
    </div>
</div>
<style>
    #tablewidget ul{
        margin: 0px;
        padding:0px;
        list-style: none;
    }
    #tablewidget ul li{
        float: left;
        margin-left: 20px;
    }
</style>
<script>

    $("#delete").click(function () {

        $(".caozuo").each(function(){

            if ($(this).is(":checked")) {
               var a =$(this).val();
                $.ajax({
                    type: "POST",
                    url: "/admin/user/del",
                    data: {id:a},
                    dataType: "json",
                    success: function(data){
                        if(data==1){
                            alert("删除成功，正在刷新")
                            location.reload();
                        }else if (data==0){
                            alert("删除失败！")
                        }
                    }

                });
            }
        });

    })
    $("#add").click(function () {
       var meunId = $("#meunId").val();
        var MenuName = $("#MenuName").val();
        if($.isEmptyObject(meunId)){
            return false;
        }
        if($.isEmptyObject(meunId)){
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/admin/user/create",
            data: {meunId:meunId, MenuName:MenuName},
            dataType: "json",
            success: function(data){
              if(data==1){
                 alert("添加成功，正在刷新")
                  location.reload();
              }else if (data==0){
                  alert("添加失败！")
              }else if(data==-1){
                  alert("出现重复数据，请重新填写！")
              }
            }

        });
    })
    $("#profiles").click(function () {
        $(".caozuo").each(function(){

            if ($(this).is(":checked")) {
                var a = $(this).val();
                $.ajax({
                    type: "POST",
                    url: "/admin/user/edit",
                    data: {id: a},
                    dataType: "json",
                    success: function (data) {
                       $("#meunIds").val(data.MeunId);
                        $("#MenuNames").val(data.MenuName);
                        $("#ids").val(data.Id);
                    }

                });
            }
            });
    })
    $("#edits").click(function () {
        $(".caozuo").each(function(){

            if ($(this).is(":checked")) {
                var a = $(this).val();
                $.ajax({
                    type: "POST",
                    url: "/admin/user/edits",
                    data: {id: a,MeunId:  $("#meunIds").val(), MenuName:$("#MenuName").val()},
                    dataType: "json",
                    success: function (data) {
                        if(data==0){
                            alert("修改失败！")
                        }else {
                            alert("修改成功！")
                        }
                    }

                });
            }
        });
    })
</script>

